#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif

#include <Debug.h>

#ifndef MEMORYCOMMUNICATION_H_INCLUDED
#define MEMORYCOMMUNICATION_H_INCLUDED

#define METHODE_GET_SINGLE_VALUE 1
#define METHODE_SET_SINGLE_VALUE 2
#define METHODE_GET_ARRAY_VALUES 3
#define METHODE_SET_ARRAY_VALUES 4

#define DATATYPE_INT8 1
#define DATATYPE_INT16 2
#define DATATYPE_INT32 3
#define DATATYPE_INT64 4 //only for due and double

#define STD_STOPINDEX 3

class MemoryCommunication
{
public :
	MemoryCommunication(Stream* _data);
	void loop();
private:
	void progress(void);
	byte internal_loop(byte b, boolean read_only, boolean *do_write);
	void get_value(byte dataType, byte *adress);
	void reset(void);
	void set_value(byte dataType, byte *adress);

	byte in_buffer[255];
	byte out_buffer[255];

	byte in_count;
	byte stop_index;

	byte out_read_index;
	byte out_write_index;

	boolean available;
	byte read_in;
	byte write_out;
	boolean do_write;

	Stream *Data;
};

#endif